package cn.andy.android.crm.common;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;

public class Util {
	
	private static final Map<String, Locale> localizations;
	
	static{
		localizations = new HashMap<String, Locale>();
		localizations.put("1", Locale.ENGLISH);
		localizations.put("2", Locale.SIMPLIFIED_CHINESE);
	}
	
	
	public static void initLocalization(Context ctx){
		Resources resources = ctx.getResources();//获得res资源对象

		Configuration config = resources.getConfiguration();//获得设置对象

		DisplayMetrics dm = resources .getDisplayMetrics();//获得屏幕参数：主要是分辨率，像素等。
		
		String locale = getPreference(ctx, "localization");

		config.locale = localizations.get(locale);

		resources.updateConfiguration(config, dm);
		
	}
	
	public static String getPreference(Context ctx, String key){
		return PreferenceManager.getDefaultSharedPreferences(ctx).getString(key, "");
	}
	
	public static boolean isNullStr(String str){
		return str == null || str.length() <= 0;
	}

}
